
import 'package:qyou_app/common/bloc.dart';
import 'package:qyou_app/common/http.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:qyou_app/model/video.dart';

class Api{
  static const nav = '/q-channel/nav';                                       // 首页顶部导航
  static const channel = '/q-channel/list';                                       // 获取所有频道
  static const carousel = '/q-carousel/list';                                 // 首页轮播图
  static const video = '/q-item/list';
  static const user = '/q-user/list';

  static const broadcast = '/dy/flutter/broadcast';                           // 首页推荐广播
                      // 首页直播视频列表
  static const lotteryConfig = '/dy/flutter/lotteryConfig';                   // 抽奖配置信息
  static const lotteryResult = '/dy/flutter/lotteryResult';                   // 点击抽奖结果
  static const yubaList = '/dy/flutter/yubaList';                             // 鱼吧列表
  static const areaList = '/static/areaTel.json';                             // 国家地区号码静态文件


  static Future<List> getVideoListData(context, [pageNum]) async{
    int currentPageNo =  BlocProvider.of<VideoPageNoCubit>(context).state;
    var value = await HttpKit().get(Api.video + "/${pageNum == null ? currentPageNo : pageNum}");
    var videoMap = value.data;
    List<Video> videoList = (videoMap as List<dynamic>).map((e) => Video.fromJson((e as Map<String, dynamic>))).toList();
    //将当前页设置成下一页，也就是获取第一页，则state=2，获取第二页，则state=3
    BlocProvider.of<VideoPageNoCubit>(context).next();
    return videoList;
  }
}